<template>
	<view class="main">
		<header-vue bgColor="transparent" :searchStatus="true">
			<template v-slot:search>
				<view class="flex search-box margin32" @click="goPage('/views/shop/search')">
					<i class="iconfont icon-search font40"></i>
					<view class="flex start font28 input">搜索</view>
				</view>
			</template>
		</header-vue>
		<view class="flex margin32" >
			 <u-swiper style="width: 680upx;" :list="bannerList" keyName="pic" :autoplay="false" @click="navTo"></u-swiper>
			<!-- <image :src="item.pic" v-for="(item,index) in bannerList" :key="index" mode="aspectFit" class="banner"></image> -->
		</view>
		<scroll-view :scroll-x="true" class="scroll-x margin32" style="margin-top: 20upx;">
			<view class="flex start">
				<view v-for="(item, index) in typeList" :key="item.name" class="flex column type"
					:class="{active: index == typeIndex}" @click="typeIndex = index">
					<view class="flex type-icon">
						<image :src="item.image" mode="aspectFit"></image>
					</view>
					<view class="font24">{{item.title}}</view>
				</view>
			</view>
		</scroll-view>
		<view v-if="!typeIndex" class="flex between goods-box margin32">
			<view class="goods" v-for="(item, index) in goodsType" :key="item.name"
				@click="goPage(`/views/shop/seckill?item=${JSON.stringify(item)}`)">
				<view class="flex between title">
					<view class="fontbold-500 font24">{{item.name}}</view>
					<i class="iconfont icon-jiantou font18"></i>
				</view>
				<view class="flex between">
					<view v-for="goodsItem in recommendList[item.key]" class="goods-item">
						<image :src="goodsItem.image"></image>
						<view v-if="!index" class="flex start font20 qiang-box">
							<image :src="IMAGE_URL + '/static/shop/shop-price-bg.png'" mode="aspectFit"></image>
							<view class="flex between" style="width: 100%;">
								<view class="flex price">
									<text>￥</text>
									<text class="font24">{{goodsItem.price}}</text>
									<!-- <text>.{{goodsItem.price.split('.')[1]}}</text> -->
								</view>
								<view class="font20 fontbold-500 qiang-txt">抢</view>
							</view>
						</view>
						<view v-else-if="index == 3" class="flex price font20">
							<text class="price-title">定金</text>
							<text>￥</text>
							<text class="font24">{{goodsItem.price}}</text>
							<!-- <text>.{{goodsItem.price.split('.')[1]}}</text> -->
						</view>
						<view v-else class="flex price font20">
							<text>￥</text>
							<text class="font24">{{goodsItem.price}}</text>
							<!-- <text>.{{goodsItem.price.split('.')[1]}}</text> -->
							<text class="font16"></text>
						</view>
					</view>
				</view>
			</view>
			
		</view>
		<view v-else class="flex between select-box margin32 font24">
			<view class="flex">
				<view class="flex form-select" @click="selectShow = !selectShow">{{ params.type || '全部'}}<i
						class="iconfont icon-down font20"></i></view>
				<view class="flex form-select" @click="selectShow = !selectShow">综合排序<i
						class="iconfont icon-down font20"></i></view>
			</view>
			<view class="flex filter-btn" @click="showFilter = true">
				<i class="iconfont icon-loudou font28"></i>
				<view>筛选</view>
			</view>
			<view class="select-modal" v-if="selectShow">
				<view v-for="item in radioArr" :key="item.value" class="flex between select-modal-item font28"
					:class="{active: params.type === item.value}" @click="params.type = item.value; selectShow = false">
					<view>{{item.name}}</view>
					<view class="flex radio">
						<i class="iconfont icon-duihao" v-if="params.type === item.value"></i>
					</view>
				</view>
			</view>
		</view>
		<view v-for="(item,index) in goodList" :key="index" class="white-box margin32" @click="goPage('/views/shop/detail?id='+item.goods_id)">
			<view class="flex start store-title font24">
				<i class="iconfont icon-store font24" style="height: 24rpx;"></i>
				<view>{{item.store_name || ''}}</view>
			</view>
			<view class="flex">
				<image :src="item.pic"></image>
				<view class="flex column between start store-info">
					<view>
						<view class="flex start">
							<view class="tag font20">自营</view>
							<view class="font28 fontbold-500">{{item.goods_name}}</view>
						</view>
						<view class="sale-num font24">已售 {{item.sale_count_base || 0}}</view>
					</view>
					<view class="flex between font20 num">
						<view class="flex price">
							<text class="font28">￥</text>
							<text class="font36">{{item.price}}</text>
							<!-- <text class="font28">.{{item.price.split('.')[0] || ''}}</text> -->
						</view>
						<view class="flex">
							<view class="flex">
								<i class="iconfont icon-like font28"></i>
								80.1%
							</view>
							<view class="flex">
								<i class="iconfont icon-comment font28"></i>
								{{item.reply_count || 0}}
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<image :src="IMAGE_URL + '/static/shop/cart.png'" class="cart" @click="goPage('/views/shop/cart')"></image>
		<u-popup :show="showFilter" mode="bottom" @close="showFilter = false" :round="28">
			<view class="flex modal-title">
				<view class="flex font36 fontbold-500">全部筛选</view>
				<i class="iconfont icon-close font32" @click="showFilter = false"></i>
			</view>
			<view class="modal-content margin32">
				<view class="sub-titile font30 fontbold-500">价格区间</view>
				<view class="flex start checkbox-box">
					<view class="flex column checkbox" v-for="item in priceBetween" :key="item.name"
						:class="{active: item.name === params.price }">
						<view class="font28">{{item.name}}</view>
						<view class="font24">{{item.des}}</view>
					</view>
				</view>
				<view class="flex between input-group">
					<input placeholder="自定义最低价" />
					<view class="line"></view>
					<input placeholder="自定义最高价" />
				</view>
				<view class="sub-titile font30 fontbold-500">品牌</view>
				<view class="flex start checkbox-box">
					<view class="flex column checkbox" v-for="item in priceBetween" :key="item.name"
						:class="{active: item.name === params.price }">
						<view class="font28">{{item.name}}</view>
						<view class="font24">{{item.des}}</view>
					</view>
				</view>
			</view>
			<view class="flex modal-footer font36 fontbold-500">
				<view class="flex clear-btn" @click="showFilter = false">清空选择</view>
				<view class="flex submit-btn" @click="showFilter = false">确定</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import headerVue from '../../components/header.vue';
	import {
		getTab, getGoodList
	} from '@/api/modules/shop.js';
	import appConfig from '@/config/app.js'

	export default {
		components: {
			headerVue
		},
		data() {
			return {
				IMAGE_URL: appConfig.IMAGE_URL,
				bannerList: [],
				recommendList: {},
				imageUrl: '~@static/shop/',
				typeIndex: 0,
				typeList: [],
				goodsType: [{
						name: '限时秒杀，超值疯抢',
						key: 'miaosha',
						index: 3,
						title: '秒杀',
						confirmUrl: '/views/shop/confirmOrder',
						query: '/miaos'
					},
					{
						name: '团购套餐，限时特惠',
						key: 'tuan',
						title: '团购',
						index: 2,
						confirmUrl: '/views/shop/confirmOrder',
						query: '/tuangou'
					},
					{
						name: '全网新品，限时特惠',
						key: 'new',
						title: '新品',
						index: 1,
						confirmUrl: '/views/shop/confirmOrder',
						query: '/newlist'
					},
					{
						name: '定金膨胀，抢先预定',
						key: 'diingj',
						title: '预售',
						index: 1,
						confirmUrl: '/views/shop/yushouOrder',
						query: '/yushou'
					}
				],
				radioArr: [{
						name: '全部',
						value: ''
					},
					{
						name: '便利店',
						value: '便利店'
					},
					{
						name: '大型超市',
						value: '大型超市'
					},
					{
						name: '甜筒专卖店',
						value: '甜筒专卖店'
					},
				],
				priceBetween: [{
						name: '14元以下',
						des: '60%的选择'
					},
					{
						name: '14-34元',
						des: '30%的选择'
					},
					{
						name: '34-79元以下',
						des: '9%的选择'
					},
					{
						name: '79元以上',
						des: '1%的选择'
					},
				],
				selectShow: false,
				showFilter: false,
				goodList:[],
				params: {
					keyword: '',
					type: ''
				}
			}
		},
		created() {
			getTab().then(res => {
				res.banner.map(item=>{
					item.pic = 'http://api.f4.huoke999.com/uploads/202508/68b1760c4908e.png'
				})
			
				this.bannerList = res.banner
				this.typeList = res.category
				this.recommendList = res.recommend
			})
			getGoodList({i:3,do:'Goods.recommend'}).then(res=>{
				console.log(res);
				this.goodList = res.data
				console.log(this.goodList);
			})
		},
		methods: {
			goPage(url) {
				uni.navigateTo({
					url
				});
			},
			navTo(e){
				console.log(e);
				this.goPage(this.bannerList[e].url)
			},
			getlist(){
				
			}
		}
		
	}
</script>

<style lang="scss" scoped>
	.main {
		background: url('https://api.f4.huoke999.com/uploads/202508/68a7ee608d211.png') no-repeat;
		background-position: top;
		background-size: contain;
	}

	.margin32 {
		margin: 0 32rpx;
	}

	.search-box {
		height: 72rpx;
		background: $uni-bg-color;
		border-radius: 60rpx;
		padding: 0 28rpx;
		margin-bottom: 28rpx;
		width: 100%;

		.iconfont {
			color: $uni-text-color-grey;
			margin-right: 20rpx;
		}

		.input {
			width: 100%;
			height: 100%;
			color: $uni-text-color-grey;
		}
	}

	.banner {
		height: 230rpx;
	}

	.scroll-x {
		padding: 28rpx 0;
		box-sizing: border-box;
		background: $uni-bg-color;
		border-radius: 20rpx;
		white-space: nowrap;
		width: auto;
		margin-bottom: 28rpx;

		.type {
			margin-left: 28rpx;
			color: $uni-text-color-grey1;

			.type-icon {
				width: 80rpx;
				height: 80rpx;
				background: #EAF7FF;
				border-radius: 50%;
				margin-bottom: 12rpx;

				image {
					width: 56rpx;
					height: 60rpx;
				}
			}
		}

		.active {
			color: $uni-text-color;
			font-weight: 500;

			.type-icon {
				// background: url($image-prefix + 'shop/shop-type-active.png') no-repeat;
				background-position: top;
				background-size: cover;
			}
		}
	}

	.goods-box {
		flex-wrap: wrap;

		.qiang-box {
			position: relative;

			image {
				width: 100%;
				position: absolute;
				z-index: 0;
				height: 100%;
			}

			.price {
				z-index: 1;
				background: none;
				margin-left: 4rpx;
			}

			.qiang-txt {
				color: #fff;
				z-index: 1;
				width: 32rpx;
			}
		}

		.goods {
			padding: 20rpx;
			box-sizing: border-box;
			background: linear-gradient(180deg, #E6F6FF 0%, #FFFFFF 20%, #FFFFFF 100%);
			box-shadow: 0rpx 0rpx 20rpx 0rpx rgba(0, 0, 0, 0.1);
			border-radius: 20rpx;
			margin: 0 22rpx 28rpx 0;
			width: calc((100% - 22rpx)/2);

			&:nth-child(2),
			&:nth-child(3) {
				background: linear-gradient(180deg, #FFF8EE 0%, #FFFFFF 20%, #FFFFFF 100%);
			}

			&:nth-child(2n) {
				margin-right: 0;
			}

			.title {
				color: #222222;
				margin-bottom: 18rpx;

				.iconfont {
					color: #111111;
				}
			}

			.goods-item {
				width: calc((50vw - 95rpx) / 2);

				image {
					width: 100%;
					height: calc((50vw - 95rpx) / 2);
					border-radius: 8rpx;
				}

				.price {
					height: 36rpx;
					background: #FFEAED;
					border-radius: 10rpx;
					color: $uni-text-color-red;
					align-items: baseline;

					.font16 {
						color: $uni-text-color-grey;
						text-decoration-line: line-through;
						margin-left: 4rpx;
					}

					.price-title {
						color: $uni-text-color;
					}
				}
			}
		}
	}

	.price {
		color: $uni-text-color-red;
		align-items: baseline;
	}

	.select-box {
		margin-bottom: 28rpx;
		position: relative;

		.form-select {
			height: 52rpx;
			padding: 0 24rpx;
			box-sizing: border-box;
			background: #FFFFFF;
			box-shadow: 0rpx 0rpx 16rpx 0rpx rgba(0, 0, 0, 0.08);
			border-radius: 60rpx 60rpx 60rpx 60rpx;
			margin-right: 28rpx;

			.icon-down {
				margin-left: 4rpx;
				color: #111111;
			}
		}

		.filter-btn {
			color: $uni-color-primary;

			.icon-loudou {
				margin-right: 4rpx;
			}
		}

		.select-modal {
			width: 100vw;
			position: absolute;
			z-index: 10;
			background: $uni-bg-color;
			border-radius: 0rpx 0rpx 28rpx 28rpx;
			left: -32rpx;
			top: 100%;
			margin-top: 8rpx;
			padding: 28rpx 32rpx;
			box-sizing: border-box;

			.select-modal-item {
				margin-top: 40rpx;
				color: $uni-text-color-grey1;

				&:nth-child(1) {
					margin: 0;
				}
			}

			.radio {
				width: 26rpx;
				height: 26rpx;
				border-radius: 50%;
				border: 1rpx solid $uni-color-primary;
			}

			.active {
				color: $uni-text-color;

				.radio {
					background: $uni-color-primary;
					color: $uni-text-color-inverse;
				}
			}
		}
	}

	.white-box {
		background: $uni-bg-color;
		box-shadow: 0rpx 0rpx 20rpx 0rpx rgba(0, 0, 0, 0.08);
		border-radius: 20rpx;
		padding: 20rpx;
		box-sizing: border-box;
		margin-bottom: 28rpx;

		.store-title {
			padding-bottom: 20rpx;
			border-bottom: 1rpx solid #DDDDDD;
			margin-bottom: 20rpx;
		}

		.iconfont {
			margin-right: 4rpx;
		}

		image {
			width: 200rpx;
			height: 200rpx;
			border-radius: 16rpx;
			margin-right: 20rpx;
			flex-shrink: 0;
		}

		.store-info {
			width: 100%;
			height: 200rpx;
			align-items: flex-start;

			.tag {
				padding: 0 8rpx;
				height: 28rpx;
				line-height: 28upx;
				box-sizing: border-box;
				background: #DF9824;
				border-radius: 4rpx;
				margin-right: 8rpx;
				color: $uni-text-color-inverse;
			}

			.sale-num {
				color: $uni-text-color-grey;
				margin-top: 20rpx;
			}

			.num {
				color: $uni-text-color-grey1;
				width: 100%;
			}

			.icon-comment {
				margin-left: 26rpx;
			}
		}
	}

	.cart {
		position: fixed;
		right: 20rpx;
		top: 70%;
		transform: translateY(-50%);
		width: 100rpx;
		height: 100rpx;
	}

	.modal-title {
		margin: 40rpx 0;

		.icon-close {
			position: absolute;
			right: 32rpx;
			top: 50rpx;
		}
	}

	.modal-content {

		.checkbox-box {
			flex-wrap: wrap;

			.checkbox {
				width: calc((100% - 36rpx) / 3);
				height: 86rpx;
				background: #F5F5F5;
				border-radius: 100rpx;
				margin-top: 40rpx;
				margin-right: 18rpx;

				&:nth-child(3n) {
					margin-right: 0;
				}

				.font24 {
					color: $uni-text-color-grey;
					margin-top: 4rpx;
				}
			}

			.active {
				background: #FFEFD5;
			}
		}

		.input-group {
			height: 86rpx;
			background: #F5F5F5;
			border-radius: 60rpx;
			margin: 40rpx 0 54rpx;

			.line {
				width: 40rpx;
				height: 1rpx;
				background: $uni-text-color-grey;
			}

			input {
				text-align: center;
			}
		}
	}

	.modal-footer {
		color: $uni-text-color-inverse;
		margin: 40rpx 0 calc(env(safe-area-inset-bottom) + 20rpx) 0;

		.clear-btn {
			width: 260rpx;
			height: 80rpx;
			background: #DF9824;
			box-shadow: 0rpx 6rpx 12rpx 0rpx rgba(223, 152, 36, 0.3);
			border-radius: 100rpx;
		}

		.submit-btn {
			width: 260rpx;
			height: 80rpx;
			background: #0785CF;
			box-shadow: 0rpx 6rpx 12rpx 0rpx rgba(7, 133, 207, 0.3);
			border-radius: 100rpx 100rpx 100rpx 100rpx;
			margin-left: 60rpx;
		}
	}
</style>